package dialer.ws.base.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "calls", schema = "call_center")
@NamedQueries({
		@NamedQuery(name = "Call.getProcesValidFinish", query = "SELECT COUNT(c) FROM Calls c WHERE c.fechaLlamada is not null AND c.status IN ('Success') AND id_campaign=:id_campaign AND retries=:retries"),
		@NamedQuery(name = "Call.getProcesInValidFinish", query = "SELECT COUNT(c) FROM Calls c WHERE c.fechaLlamada is not null AND c.status IN ('Placing','ShortCall','Abandoned','Failure')  AND id_campaign=:id_campaign AND retries=:retries"),
		@NamedQuery(name = "Call.getEnGestion", query = "SELECT COUNT(c) FROM Calls c WHERE c.fechaLlamada is not null AND c.status IN ('Placing','ShortCall','Abandoned','Failure','OnQueue')  AND id_campaign=:id_campaign AND retries<:retries"),
		@NamedQuery(name = "Call.getNoGestionado", query = "SELECT COUNT(c) FROM Calls c WHERE c.fechaLlamada is not null AND STATUS IS NULL AND id_campaign=:id_campaign AND retries<:retries"),
		@NamedQuery(name = "Call.getTotalProcesGestion", query = "SELECT COUNT(c) FROM Calls c WHERE c.fechaLlamada is not null AND id_campaign=:id_campaign AND retries<:retries") })
public class Calls implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5212976327650561389L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id", unique = true, nullable = false)
	private Integer id;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_agent")
	private Agent agent;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_campaign", nullable = false)
	private Campaign campaign;

	@Column(name = "phone", nullable = false)
	private String phone;

	@Column(name = "status")
	private String status;

	@Column(name = "uniqueid")
	private String uniqueid;

	@Column(name = "fecha_llamada")
	private Date fechaLlamada;

	@Column(name = "start_time")
	private Date startTime;

	@Column(name = "end_time")
	private Date endTime;

	@Column(name = "retries", nullable = false)
	private Integer retries;

	@Column(name = "duration")
	private Integer duration;

	@Column(name = "transfer")
	private String transfer;

	@Column(name = "datetime_entry_queue")
	private Date datetimeEntryQueue;

	@Column(name = "duration_wait")
	private Integer durationWait;

	@Column(name = "dnc")
	private Integer dnc;

	@Column(name = "date_init")
	private Date dateInit;

	@Column(name = "date_end")
	private Date dateEnd;

	@Column(name = "time_init")
	private Date timeInit;

	@Column(name = "time_end")
	private Date timeEnd;

	@Column(name = "agent")
	private String agent_1;

	@Column(name = "failure_cause")
	private Integer failureCause;

	@Column(name = "failure_cause_txt")
	private String failureCauseTxt;

	@Column(name = "datetime_originate")
	private Date datetimeOriginate;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "calls")
	private List<FormDataRecolected> listFormDataRecolected;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "calls")
	private List<CurrentCalls> listCurrentCalls;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "calls")
	private List<CallAttribute> listCallAttribute;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Agent getAgent() {
		return agent;
	}

	public void setAgent(Agent agent) {
		this.agent = agent;
	}

	public Campaign getCampaign() {
		return campaign;
	}

	public void setCampaign(Campaign campaign) {
		this.campaign = campaign;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getUniqueid() {
		return uniqueid;
	}

	public void setUniqueid(String uniqueid) {
		this.uniqueid = uniqueid;
	}

	public Date getFechaLlamada() {
		return fechaLlamada;
	}

	public void setFechaLlamada(Date fechaLlamada) {
		this.fechaLlamada = fechaLlamada;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Integer getRetries() {
		return retries;
	}

	public void setRetries(Integer retries) {
		this.retries = retries;
	}

	public Integer getDuration() {
		return duration;
	}

	public void setDuration(Integer duration) {
		this.duration = duration;
	}

	public String getTransfer() {
		return transfer;
	}

	public void setTransfer(String transfer) {
		this.transfer = transfer;
	}

	public Date getDatetimeEntryQueue() {
		return datetimeEntryQueue;
	}

	public void setDatetimeEntryQueue(Date datetimeEntryQueue) {
		this.datetimeEntryQueue = datetimeEntryQueue;
	}

	public Integer getDurationWait() {
		return durationWait;
	}

	public void setDurationWait(Integer durationWait) {
		this.durationWait = durationWait;
	}

	public Integer getDnc() {
		return dnc;
	}

	public void setDnc(Integer dnc) {
		this.dnc = dnc;
	}

	public Date getDateInit() {
		return dateInit;
	}

	public void setDateInit(Date dateInit) {
		this.dateInit = dateInit;
	}

	public Date getDateEnd() {
		return dateEnd;
	}

	public void setDateEnd(Date dateEnd) {
		this.dateEnd = dateEnd;
	}

	public Date getTimeInit() {
		return timeInit;
	}

	public void setTimeInit(Date timeInit) {
		this.timeInit = timeInit;
	}

	public Date getTimeEnd() {
		return timeEnd;
	}

	public void setTimeEnd(Date timeEnd) {
		this.timeEnd = timeEnd;
	}

	public String getAgent_1() {
		return agent_1;
	}

	public void setAgent_1(String agent_1) {
		this.agent_1 = agent_1;
	}

	public Integer getFailureCause() {
		return failureCause;
	}

	public void setFailureCause(Integer failureCause) {
		this.failureCause = failureCause;
	}

	public String getFailureCauseTxt() {
		return failureCauseTxt;
	}

	public void setFailureCauseTxt(String failureCauseTxt) {
		this.failureCauseTxt = failureCauseTxt;
	}

	public Date getDatetimeOriginate() {
		return datetimeOriginate;
	}

	public void setDatetimeOriginate(Date datetimeOriginate) {
		this.datetimeOriginate = datetimeOriginate;
	}

	public List<FormDataRecolected> getListFormDataRecolected() {
		return listFormDataRecolected;
	}

	public void setListFormDataRecolected(List<FormDataRecolected> listFormDataRecolected) {
		this.listFormDataRecolected = listFormDataRecolected;
	}

	public List<CurrentCalls> getListCurrentCalls() {
		return listCurrentCalls;
	}

	public void setListCurrentCalls(List<CurrentCalls> listCurrentCalls) {
		this.listCurrentCalls = listCurrentCalls;
	}

	public List<CallAttribute> getListCallAttribute() {
		return listCallAttribute;
	}

	public void setListCallAttribute(List<CallAttribute> listCallAttribute) {
		this.listCallAttribute = listCallAttribute;
	}

}